﻿namespace StreetCrime.Models
{
    using System;
    using Serialization;
    using WP7Contrib.Common;

    [Serializer(typeof(StreetLevelCrimeStreet))]
    public sealed class StreetLevelCrimeStreet : BaseModel, ISerializeObject, IEquatable<StreetLevelCrimeStreet>
    {
        private int id;

        private string name;

        private string description;

        public StreetLevelCrimeStreet()
        {
        }

        public object[] Serialize(object target)
        {
            var street = (StreetLevelCrimeStreet)target;
            return new object[] { street.Id,
                                  street.Name,
                                  street.Description };
        }

        public object Deserialize(object[] data)
        {
            var street = new StreetLevelCrimeStreet
            {
                Id = (int)data[0],
                Name = (string)data[1],
                Description = (string)data[2]
            };

            return street;
        }

        public int Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.id, value, () => this.Id);
            }
        }

        public string Description
        {
            get
            {
                return this.description;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.description, value, () => this.Description);
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.SetPropertyAndNotify(ref this.name, value, () => this.Name);
            }
        }

        public static bool operator ==(StreetLevelCrimeStreet slcs1, StreetLevelCrimeStreet slcs2)
        {
            return Equals(slcs1, slcs2);
        }

        public static bool operator !=(StreetLevelCrimeStreet slcs1, StreetLevelCrimeStreet slcs2)
        {
            return !Equals(slcs1, slcs2);
        }

        public bool Equals(StreetLevelCrimeStreet street)
        {
            if (ReferenceEquals(null, street))
            {
                return false;
            }

            if (this.Id != street.Id)
            {
                return false;
            }

            if (this.Name != street.Name)
            {
                return false;
            }

            return true;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            return obj is StreetLevelCrimeStreet && this.Equals((StreetLevelCrimeStreet)obj);
        }

        public override int GetHashCode()
        {
            return this.CombineHashCodes(this.Id, this.Name);
        }
    }
}